const AblumsModel = require("../models/AblumsModel")


const AblumsService = {
    //添加图片
    img_add: async (data, imgs) => {
        return await AblumsModel.create({
            year: data.y,
            month: data.m,
            day: data.d,
            Albumbs: imgs
        })
    },
    find_day: async (data) => {
        return await AblumsModel.findOne({
            year: data.y,
            month: data.m,
            day: data.d
        })
    },
    updata_img: async (data, imgs) => {
        return await AblumsModel.findOneAndUpdate({
            year: data.y,
            month: data.m,
            day: data.d
        }, {
            $push: { Albumbs: { $each: imgs, $position: 0 } }
        })
    },
    find_imgs: async (data) => {
        return await AblumsModel.find({
            year: data.year,
            month: data.month
        }).skip(data.id).limit(2).sort({ day: 'desc' }).select('-__v')
    },
    delete_img: async (data) => {
        return await AblumsModel.updateOne({
            year: data.year,
            month: data.month,
            day: data.day
        }, {
            $pull: {
                Albumbs: data.img
            }
        })
    }

}


module.exports = AblumsService